<template>
    <div>
        <Row>
            <i-col span="24">
                <Card>
                    <Button class="opt-btn" @click="showAddModal" type="primary">添加</Button>
                    <Dropdown class="opt-btn" @on-click="batchOpt">
                        <Button type="primary">
                            批量操作
                            <Icon type="ios-arrow-down"></Icon>
                        </Button>
                        <DropdownMenu slot="list">
                            <DropdownItem name="batchActive">批量激活</DropdownItem>
                            <DropdownItem name="batchInactive"><span style="color: red;">批量冻结</span></DropdownItem>
                            <DropdownItem name="batchRemove" divided><span style="color: red;">批量删除</span></DropdownItem>
                        </DropdownMenu>
                    </Dropdown>
                    <Button class="opt-btn" @click="showSearchModal" type="primary">高级搜索</Button>
                    <Tooltip class="opt-btn" content="刷新" placement="right">
                        <Button icon="md-refresh" type="success" shape="circle" @click="searchTable(false)"></Button>
                    </Tooltip>
                    <Tooltip class="opt-btn" content="重置搜索" placement="right">
                        <Button icon="md-repeat" type="success" shape="circle" @click="researchTable"></Button>
                    </Tooltip>
                    <FundsTransferTableMain ref="table" v-on:searchTable="searchTable"
                    v-on:showEditModal="showEditModal"
                    v-on:showDetailModal="showDetailModal"
                    v-on:showModuleDetail="userModuleDetail" 
                    v-on:showModuleSearch="userModuleSearch"/>
                </Card>
            </i-col>
        </Row>
        <FundsTransferAddEditModal ref="addEditModal" v-on:add="add" v-on:edit="edit"/>
        <FundsTransferSearchModal ref="searchModal" v-on:searchTable="searchTable"/>
        <FundsTransferDetailModal ref="detailModal"/>
        <UserUserDetailDetailModal ref="moduleDetail" />
        <!-- 搜索用户 -->
         <Modal
          v-model="modal.moduleSearch"
          title="用户查询"
          :mask-closable="false"
          width="1020"
        >
          <UserUserDetailMainSingle 
            ref="moduleSearch"
            v-on:confirmChoice="confirmChoice"
          />
          <div slot="footer">
            <Button type="text" size="large" @click="cancelModal('moduleSearch')">取消</Button>
            <Button type="primary" size="large" @click="bottomConfirmChoice">确认选择</Button>
          </div>
        </Modal>
    </div>
</template>

<script>
    import * as utils from '@/api/utils-v2'
    import * as ResponseStatus from '@/api/response-status'
    import UserUserDetailMainSingle from '../user-userdetail/UserUserDetailMainSingle.vue'
    import UserUserDetailDetailModal from '../user-userdetail/UserUserDetailDetailModal.vue'
    import FundsTransferTableMain from './FundsTransferTableMain.vue'
    import FundsTransferAddEditModal from './FundsTransferAddEditModal.vue'
    import FundsTransferSearchModal from './FundsTransferSearchModal.vue'
    import FundsTransferDetailModal from './FundsTransferDetailModal.vue'
    export default {
        name: 'FundsTransferMain',
        components: {
            UserUserDetailDetailModal,
            UserUserDetailMainSingle,
            FundsTransferTableMain,
            FundsTransferAddEditModal,
            FundsTransferSearchModal,
            FundsTransferDetailModal
        },
        data() {
            return {
                modal: {
                    moduleSearch:false
                },
                urls: {
                    oneUrl: '/user-userdetail/admin/multi/',
                    batchRemoveUrl: '/funds-transfer/admin/batch-remove',
                    batchActiveUrl: '/funds-transfer/admin/batch-active'
                },
                userType:0,  //用户筛选类型  0：用户  1：交易转出方   2：交易收款方
            }
        },
        computed: {},
        mounted() {},
        methods: {
            searchTable(reset) {
                utils.search(this, reset)
            },
            researchTable() {
                this.$refs.searchModal.resetForm()
                setTimeout(() => {
                    utils.search(this, true)
                }, 10);
            },
            /**
             * 显示用户模块详情
             */
            userModuleDetail(id) {
              utils
                .doGet(this.urls.oneUrl + id, {})
                .then(res => {
                  if (ResponseStatus.OK === res.data.code) {
                    let moduleDetail = this.$refs.moduleDetail
                    moduleDetail.form = res.data.data.rows[0]
                    moduleDetail.modal.detail = true
                    moduleDetail.getDictItemsDisplayValue()
                  } else {
                    this.$Message.error(res.data.message)
                  }
                })
                .catch(err => {
                  console.log(err)
                })
            },
            /**
             * 显示用户模块搜索
             */
            userModuleSearch(userType) {
              //用户筛选类型  userType >> 0用户 1：交易转出方 2：交易收款方
              this.userType = userType 
              this.showModal('moduleSearch')
              this.$refs.moduleSearch.searchTable(true)
            },
            /**
             * 底部的确认选择
             */
            bottomConfirmChoice() {
              this.$refs.moduleSearch.confirmSelection()
            },
             /**
             * 确认选择
             */
            confirmChoice(row) {
                this.cancelModal('moduleSearch')
                let searchModal = this.$refs.searchModal
                if(this.userType == 0){  
                    //用户搜索
                    searchModal.searchForm.userIdMin =  row.userId
                    searchModal.searchForm.userIdMax =  row.userId  
                    searchModal.searchForm.fromUserIdMin =  null
                    searchModal.searchForm.fromUserIdMax =  null
                    searchModal.searchForm.toUserIdMin =  null
                    searchModal.searchForm.toUserIdMax = null                
                }else if(this.userType == 1){  
                    //交易转出方 搜索
                    searchModal.searchForm.fromUserIdMin =  row.userId
                    searchModal.searchForm.fromUserIdMax =  row.userId   
                    searchModal.searchForm.userIdMin = null
                    searchModal.searchForm.userIdMax =  null 
                    searchModal.searchForm.toUserIdMin =  null
                    searchModal.searchForm.toUserIdMax = null                   
                }else if(this.userType == 2){
                    //交易收款方 搜索
                    searchModal.searchForm.toUserIdMin =  row.userId
                    searchModal.searchForm.toUserIdMax =  row.userId   
                    searchModal.searchForm.userIdMin = null
                    searchModal.searchForm.userIdMax =  null
                    searchModal.searchForm.fromUserIdMin = null
                    searchModal.searchForm.fromUserIdMax =  null    
                }                
               this.searchTable()
            },
            showModal(modal) {
              utils.showModal(this, modal)
            },
            cancelModal(modal) {
              utils.cancelModal(this, modal)
            },
            showAddModal() {
                let addEditModal = this.$refs.addEditModal
                addEditModal.modal.add = true
            },
            add() {
                utils.add(this)
            },
            showEditModal(row) {
                let addEditModal = this.$refs.addEditModal
                addEditModal.modal.edit = true
                row.version = null
                row.createTime = null
                row.updateTime = null
                addEditModal.form = row
            },
            edit() {
                utils.edit(this)
            },
            showDetailModal(row) {
                let detailModal = this.$refs.detailModal
                detailModal.modal.detail = true
                detailModal.form = row
				detailModal.getDictItemsDisplayValue()
            },
            showSearchModal() {
                let searchModal = this.$refs.searchModal
                searchModal.modal.search = true
            },
            batchOpt(itemName) {
                if (itemName === 'batchActive') {
                    utils.batchActive(this, 0)
                } else if (itemName === 'batchInactive') {
                    utils.batchActive(this, 1)
                } else if (itemName === 'batchRemove') {
                    utils.batchRemove(this)
                }
            }
        }
    }
</script>

<style>
</style>
